-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory leak when img onerror/onload callbacks reference img #1003
Conversation
Storing the onerror/onload callbacks in Persistent handles means they will never be GC'ed. If those functions have references to the image, then the image will never be GC'ed either. Fixes Automattic#785 Fixes Automattic#150 (for real)
I think I understand this better now (or I'm even more confused and this is all wrong, but at the moment I've convinced myself). The first paragraph of my OP is correct and explains the leak. In addition... node-canvas's A third consequence is that Summary:
|
I really think that it should be asynchronous, since in most cases it is performing blocking io as it is now. It will also be unacceptable to be synchronous when/if we support I think that the minimum we should to before releasing 2.0 is to just add
This is a bit unfortunate but I think 2.x is a good time to break things. In the end, I hope it will lead to better practices...
I feel that this comes down to io vs cpu. My opinion is that io work should be async and cpu work should be sync. That callbacks adds a bit of overhead is just how Node.js works, the same can be said for e.g.
Sounds good 👍 |
Yeah, that's most logical, I agree. Will open another ticket for it. |
Thx for the excellent works! |
published as 2.0.0-alpha.6 |
Storing the
onerror
/onload
callback functions in Persistent handles (here, asNan::Callback
s) means they will never be GC'ed automatically; only when the Image destructor runs, which explicitly resets them. But, if those functions have references to the image, then the image will never be GC'ed. --> leakI'm annoyed that I can't figure out how to do this from C++ after thinking about it all day. I have an open message on the v8-users list to see if there's a way, but this method also removes 87 lines of code. The only benefit to doing it in C++ is that we can type check the value and only set it if it's a function. Up to you if you want to wait a bit to see if someone responds.
Fixes #785
Fixes #150 (for real)
Code that repros the leak:
In master:
24535040
466857984
908058624
1347592192
This PR:
24571904
26157056
26300416
25919488
24920064